package com.canal.admin.controller;

import com.canal.admin.response.Result;
import com.canal.admin.response.ResultUtil;
import com.canal.admin.service.ChannelBaseService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangbo
 * @date 2020-07-23 14:08
 */
@RestController
public class BaseDataController {

    @Autowired
    private ChannelBaseService channelBaseService;

    @GetMapping(value = "/base/channels")
    @PreAuthorize("isAuthenticated()")
    public Result channels(@RequestParam(value = "keyword",required = false) String keyword) {
        if(StringUtils.isBlank(keyword)) {
            keyword = "";
        }
        return ResultUtil.makeSuccess(channelBaseService.channelList(keyword));
    }

    @GetMapping(value = "/base/items")
    @PreAuthorize("isAuthenticated()")
    public Result items(@RequestParam(value = "keyword",required = false) String keyword) {
        if(StringUtils.isBlank(keyword)) {
            keyword = "";
        }
        return ResultUtil.makeSuccess(channelBaseService.channelItemList(keyword));
    }
}
